#ifndef MESSAGE_HPP_
# define MESSAGE_HPP_

# include "Utils/ISerializable.hpp"
# include "Utils/macros.hpp"

namespace pizzeria {
namespace communication {

/*! Message send through WalkieTalkie between Reception and Kitchens */
class Message: public utils::ISerializable {
public:
  /*! Available message types */
  typedef enum {
    NONE, /*!< No message */
    NEW_ORDER, /*!< New pizza order */
    GET_STATUS, /*!< Ask for the status of a kitchen */
    STATUS /*!< Return a kitchen status */
  } Type;

  /*! Default constructor - construct a Message of type NONE */
  Message();
  /*! Constructor
   * \param type : type of the message
   * \param data : the data of the message (if type differs from NONE
   * 		   or NEW_ORDER)
   */
  Message(Type type, utils::ISerializable *data = NULL);
  /*! Copy constructor
   * \param toCopy : object to copy
   */
  Message(const Message &toCopy);
  /*! Destructor */
  ~Message();

  /*! Assignment operator
   * \param toCopy : object to copy
   * \return *this
   */
  Message &operator =(const Message &toCopy);

  /*! Serialize the object
   * \return a std::string representing the serialized data
   */
  std::string Serialize() const;
  /*! Deserialize the object
   * \param data : data to deserialize
   */
  void Deserialize(const std::string &data);

  /*! Get the message data
   * \ŕeturn the message data
   */
  const utils::ISerializable* GetData() const;
  /*! Get the message type
   * \return the message type
   */
  Type GetType() const;
  /*! Set the message data
   * \param data : the message data
   */
  void SetData(utils::ISerializable *data);
  /*! Set the message type
   * \param type : the message type
   */
  void SetType(Type type);
  /*! Get size of serialized data
   * \return size of serialized data
   */
  size_t GetSerializedSize() const;

private:
  Type mType; /*!< Message type */
  utils::ISerializable *mData; /*!< Message data */
  bool mAllocatedRessources; /*!< Allocated ressources needs to be freed? */
};

} /* !namespace communication */
} /* !namespace pizzeria */
#endif /* !MESSAGE_HPP_ */
